<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB;
use Hash;
use Mail;
use Gregwar\Captcha\CaptchaBuilder;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class KefuController extends Controller
{
   public function getIndex()
   {
        // return 'avadsd';
        return view('home.kefu.index');
   }

   public function postAjax(Request $request)
   {
        $content = $request->input('a');
        $speaker_id = 1;
        // $round = time();
        $data['content'] = $content;
        $data['speaker_id'] = $speaker_id;
        $data['round'] = $_SERVER["REMOTE_ADDR"];
        $data['time'] = time();

        $res =  DB::table('hs_kefu')->insert($data);
        if($res){
            echo 1;
        }else{
            echo 0;
        } 
   }

    public function postGetcon()
   {
        // $res = DB::table('hs_kefu')->where('round','=',$_SERVER["REMOTE_ADDR"])->orderBy('time', 'asc')->get();
        $res = DB::table('hs_kefu')->orderBy('time', 'asc')->get();

        // ->where('round','=',$_SERVER["REMOTE_ADDR"])

        // dd($res);
        return $res;
       
   }

   public function postGetnum()
   {
         // $res = DB::table('hs_kefu')->get();
    // $users = DB::select('select * from users where active = ?', [1]);
        $num = DB::select('select count(*) as num from hs_kefu');
        echo $num[0]->num;
   }
}